﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using Newtonsoft.Json;
using System.Configuration;

public partial class Spa_wodeyuyue : WeiPage
{
    SubcribeBO sbo = new SubcribeBO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string personno = Request.QueryString["personNo"];
            string url = string.Format(@"{0}/booking/getstatuslist.do/{1}/{2}/{3}",ConfigurationManager.AppSettings["yuyue"], personno, "2014-01-01", DateTime.Now.AddDays(60).ToString("yyyy-MM-dd"));
            List<Model> list = GetData(url);
            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].Status != 0)
                    {
                        bool b = sbo.Update(list[i].BookingId, list[i].Status);
                        if (b == true)
                        {
                            GetDD(list[i].BookingId, i);
                        }

                    }
                    else
                    {
                        GetDD(list[i].BookingId, i);
                    }
                }
            }
            //else
            //{
            //    showdiv.Visible = true;

            //}

        }

    }


    private void GetDD(int bookingid,int i)
    {
        string type = "";
        Subcribe sub = sbo.GetModel(bookingid);
        if (sub == null)
        {
            i++;
            showdiv.InnerText = "您还没有历史预约记录。";
           
        }

        else
        {
           
            if (sub.Type == 0)
            {
                type = "已预约";
            }
            else if (sub.Type == 1)
            {
                type = "已通知";

            }
            else if (sub.Type == 2)
            {
                type = "已开单";

            }
            else if (sub.Type == 3)
            {
                type = "已结账";

            }
            else if (sub.Type == 7)
            {
                type = "爽约";

            }
            else if (sub.Type == 8)
            {
                type = "预约不进";

            }
            else if (sub.Type == 9)
            {
                type = "已取消";

            }
            if (type.Equals("已预约") || type.Equals("已通知"))
            {
                showdiv.Visible = false;
                ul.InnerHtml += string.Format(@"<li>
      <em>{0}</em>
       <span><i class='xiala'></i></span><strong>项目：{1}</strong>
<bdo>{2} {3}</bdo></li>
 <ol>
     
      <p>编号：{4}</p>
      <p>店名：{5}</p>     
      <p>提交时间：{6}</p>
      <a href='tel:{7}' class='xiugaibtn' >修改</a>
      </ol> ", type, sub.Item, sub.YyDate, sub.YyTime, sub.BookingId, sub.StoreName, sub.TjTime,sub.Storetel);
            }
            else
            {
                showdiv.Visible = false;
                ul.InnerHtml += string.Format(@"<li>
      <em>{0}</em>
       <span><i class='xiala'></i></span><strong>项目：{1}</strong>
<bdo>{2} {3}</bdo></li>
 <ol>
     
      <p>编号：{4}</p>
      <p>店名：{5}</p>
     
      <p>提交时间：{6}</p>
      </ol> ", type, sub.Item, sub.YyDate, sub.YyTime, sub.BookingId, sub.StoreName, sub.TjTime);

            }

        }

    }

    private List<Model> GetData(string url)
    {
        string inter = url;
        string json = PostRequest(inter);
        Data data = JsonConvert.DeserializeObject<Data>(json);
        if (data.status == 0)
        {
            List<Model> list = new List<Model>();
            for (int i = 0; i < data.data.Count; i++)
            {
                Model model = data.data[i];
                list.Add(model);
            }
            return list;
        }
        else
        {

            Response.Write("接口调用失败");
            return null;
        }
    }

    class Data
    {
        public List<Model> data;
        public int status;
        public string message;
        public Data()
        {
            data = new List<Model>();
        }
    }

    class Model
    {
        public int BookingId;
        public string UserCard;
        public int SubBranchId;
        public string SubBranchName;
        public string MasseurId;
        public string MasseurName;
        public string StartTime;
        public string EndTime;
        public int Status;
    }

    public void AlertMessage(string message)
    {
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alertCloseReload", "<script>alert(\"" + message + "\");</script>");
    }

}